package com.itheima;

import org.testng.annotations.Test;

import java.util.Comparator;
import java.util.HashMap;
import java.util.TreeMap;

public class TreeMapDemo {
    public static void main(String[] args) {
        test1();
    }
    public static void test1() {
        TreeMap<Student, String> treeMap = new TreeMap<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o2.getAge() - o1.getAge();
            }
        });
        treeMap.put(new Student("小王", 18), "北京");
        treeMap.put(new Student("小李", 19), "上海");
        treeMap.put(new Student("小张", 20), "广州");
        treeMap.put(new Student("小赵", 21), "深圳");
        treeMap.forEach((k, v) -> System.out.println(k + ":" + v));
    }

    @Test
    private static void test0() {
        TreeMap<Student, String> treeMap = new TreeMap<>();
        treeMap.put(new Student("小王", 18), "北京");
        treeMap.put(new Student("小李", 19), "上海");
        treeMap.put(new Student("小张", 20), "广州");
        treeMap.put(new Student("小赵", 21), "深圳");
        treeMap.forEach((k, v) -> System.out.println(k + ":" + v));

        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("小马", "宜宾");
    }
}
